package com.qzsoft.zhjd.common.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @ClassName: FunctionUtils
 * @Description: 工具类
 * @author linhuawei
 * @since 2021-04-23
 */
public class FunctionUtils {

    /**
     * @Title md5L32
     * @Description 32位md5加密处理
     * @param str 需要加密的字符串
     * @return 加密后的字符串
     */
    public static String md5L32(String str) {
        // 密码加密
        byte[] secretBytes = null;
        try {
            secretBytes = MessageDigest.getInstance("md5").digest(str.getBytes());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("md5加密失败");
        }

        // 16进制数字，如果生成数字未满32位，需要前面补0
        String md5code = new BigInteger(1, secretBytes).toString(16);
        for (int i = 0, len = 32 - md5code.length(); i < len; i++) {
            md5code = "0" + md5code;
        }
        return md5code;
    }

}
